//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package zmh.util;

import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;

import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
public class JsonUtil {
    private static ObjectMapper mapper = new ObjectMapper();

    private JsonUtil() {
    }

    public static String write2JsonStr(Object o) {
        try {
            return mapper.writeValueAsString(o);
        } catch (JsonProcessingException var2) {
            log.error("write2JsonStr, JsonUtil exception", var2);
            return "";
        }
    }

    public static Object json2Object(String json, Class<?> clazz) {
        try {
            return mapper.readValue(json, clazz);
        } catch (Exception var3) {
            log.error("json2Object, JsonUtil exception, json is:" + json, var3);
            return null;
        }
    }

    public static List<?> json2ArrayObject(String json, TypeReference<?> tr) {
        try {
            return (List)mapper.readValue(json, tr);
        } catch (Exception var3) {
            log.error("json2ArrayObject, JsonUtil exception, json is:" + json, var3);
            return null;
        }
    }

    public static Map<String, Object> json2Map(String json) {
        try {
            return (Map)(StringUtils.isEmpty(json) ? new HashMap() : (Map)mapper.readValue(json, Map.class));
        } catch (Exception var2) {
            log.error("json2Map, JsonUtil exception, json is:" + json, var2);
            return new HashMap();
        }
    }

    public static List<Map<String, Object>> jsonArray2List(String jsonArray) {
        try {
            return (List)mapper.readValue(jsonArray, List.class);
        } catch (Exception var2) {
            log.error("jsonArray2List, JsonUtil exception, json is:" + jsonArray, var2);
            return new ArrayList();
        }
    }

    public static JsonNode json2Node(String json) {
        try {
            return (JsonNode)mapper.readValue(json, JsonNode.class);
        } catch (Exception var2) {
            log.error("json2Node, JsonUtil exception, json is:" + json, var2);
            return null;
        }
    }

    public static void node2Writer(Writer writer, JsonNode node) {
        try {
            mapper.writeValue(writer, node);
        } catch (Exception var3) {
            log.error("node2Writer, JsonUtil exception, json is:" + node, var3);
        }

    }

    static {
        mapper.setSerializationInclusion(Include.NON_NULL);
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE).setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
    }
}
